package ar.com.fiuba.application.impl;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import ar.com.fiuba.application.api.DataSource;

/**
 * Class for a datasource coming from a raw text file
 * 
 */
public class FileDataSource implements DataSource {

	private String nextWord;

	private BufferedReader reader;

	public FileDataSource(String path) throws IOException {
		FileReader file = new FileReader(path);
		reader = new BufferedReader(file);
		readNextWord();
	}

	public String getNextWord() {
		String ret = nextWord;
		readNextWord();
		return ret;
	}

	public Boolean hasDataLeft() {
		return nextWord != null;
	}

	private void readNextWord() {
		try {
			nextWord = reader.readLine();
		} catch (IOException e) {
			nextWord = null;
		}
	}

}
